<template>
  <div id="app">
    <transition
      name="custom-classes-transition"
      :enter-active-class="enterActiveClass"
      :leave-active-class="leaveActiveClass"
    >
      <router-view></router-view>
    </transition>
  </div>
</template>

<script>
  import './app/base';
  import "./app/app.scss";
  
  const enterActiveClassRight = 'animated fadeInRight faster fixed-top';
  const leaveActiveClassLeft = 'animated fadeOutLeft faster';
  const enterActiveClassLeft = 'animated fadeInLeft faster fixed-top';
  const leaveActiveClassRight = 'animated fadeOutRight faster';
  
  
  export default {
    data() {
      return {
        enterActiveClass: enterActiveClassRight,
        leaveActiveClass: leaveActiveClassLeft,
      }
    },
    watch: {
      '$route'(to, from) {
        
        const toDepth = to.path.split('/').length;
        const fromDepth = from.path.split('/').length;
        
        if (to.path.indexOf("/admin") === -1) { //前台
          
          this.enterActiveClass = toDepth < fromDepth ? enterActiveClassLeft : enterActiveClassRight;
          this.leaveActiveClass = toDepth < fromDepth ? leaveActiveClassRight : leaveActiveClassLeft;
        } else { //后台
          
          this.enterActiveClass = toDepth < fromDepth ? enterActiveClassLeft : enterActiveClassRight;
          this.leaveActiveClass = toDepth < fromDepth ? leaveActiveClassRight : leaveActiveClassLeft;
        }
      }
    },
    components: {},
    methods: {
      getInfo() {
        let $this = this;
        
        //获取登录状态
        this.$store.dispatch("setIsLogin", !!getCookie("token"));
        
        let cfgData = false;
        let cfgDataCache = sessionStorage.getItem("cfgData");
        if (cfgDataCache !== "undefined") {
          cfgData = JSON.parse(cfgDataCache);
        }
        if (cfgData) {
          $this.$store.dispatch("setCfgData", cfgData);
        } else {
          fPost('api/config/getConfigData', {}, function (res) {
            if (typeof res.data === 'undefined') {
              res.data = [];
            }
            sessionStorage.setItem("cfgData", JSON.stringify(res.data));
            $this.$store.dispatch("setCfgData", res.data);
          });
        }
      },
    },
    mounted: function () {
      
      this.getInfo();
    },
  }
</script>

<style lang="scss">
  @import "../node_modules/animate.css";
  @import "../node_modules/_zico@1.5.1@zico/css/zico.min.css";
</style>
